<?php
/**
 * MAF
 **
 * File:
**/

/**
 * Class: MAF: E2E
 **
 * @package MAF
 * @subpackage Core
**/
abstract class maf__e2e {

	/**
	 * @throws maf__e__php_exception
	 **
	 * @param integer $_code_
	 * @param string  $_message_
	 * @param string  $_file_
	 * @param integer $_line_
	 * @param array   $_variables_
	**/
	static public function catchError($_code_, $_message_, $_file_, $_line_, array &$_variables_) {

		throw new maf__e__php_exception(
			(integer) $_code_,
			(string)  $_message_,
			(string)  $_file_,
			(integer) $_line_,
			$_variables_
		);

	}	# Function

	/**
	 * @param exception
	**/
	static public function catchException( exception $_ ) {

		try {

			static $codes = array(
				E_ERROR           => "PHP Error",
				4096              => "PHP Error",
				E_WARNING         => "PHP Warning",
				E_NOTICE          => "PHP Notice",
				E_PARSE           => "Parsing Error",
				E_CORE_ERROR      => "Core Error",
				E_CORE_WARNING    => "Core Warning",
				E_COMPILE_ERROR   => "Compile Error",
				E_COMPILE_WARNING => "Compile Warning",
				E_USER_ERROR      => "User Error",
				E_USER_WARNING    => "User Warning",
				E_USER_NOTICE     => "User Notice",
				E_STRICT          => "Runtime Strict Notice"
			);

			$message = sprintf(
				"%s%s:\n%s\nException has been caught by %s::%s() in %s%s",
				ini_get("error_prepend_string"),
				isset($codes[$_->getCode()]) ? $codes[$_->getCode()] : "Unknown",
				$_->__toString(),
				__CLASS__,
				__FUNCTION__,
				__FILE__,
				ini_get("error_append_string")
			);

			if( ini_get("log_errors_max_len") != 0 ) {
				$message = substr($message, 0, ini_get("log_errors_max_len")); }

			try {

			if( ini_get("log_errors") ) {
				error_log($message); }

			} catch( exception $e ) {}

			if( ini_get("display_errors") ) {
				echo $message; }

			switch( $_->getCode() ) {

			case E_ERROR:
			case E_CORE_ERROR:
			case E_COMPILE_ERROR:
			case E_USER_ERROR:
			case 4096:
				exit;
				break;

			}	# switch

		} catch( exception $e ) {

			echo $e;

		}	# try

	}	# Function

}	# Class

/* EOF */